package com.newa.actions;

import org.apache.log4j.Logger;
import org.hibernate.Session;

import com.newa.beans.Section;
import com.newa.dao.DAOSection;
import com.newa.listeners.Listener;
import com.newa.utils.HibUtil;
import com.opensymphony.xwork2.ActionSupport;

public class addSection extends ActionSupport {
	private Logger LOG = Logger.getLogger(addSection.class);
	private Section section;

	@Override
	public String execute() throws Exception {
		Session session = HibUtil.getSessionFactory().openSession();
		DAOSection daos = new DAOSection(session);
		boolean res;
		try {
			res = daos.createSection(section);
		} catch (Exception e) {
			LOG.warn(e);
			throw new RuntimeException(e);
		} finally {
			daos.closeSession().close();
		}
		
		if (res) {
			return "success";
		}
		return "error";
	}

	public Section getSection() {
		return section;
	}

	public void setSection(Section section) {
		this.section = section;
	}

}
